

jQuery(function ($) {
    var onoff = false;
    var pageOnoff = true;
    var user = JSON.parse(localStorage.getItem('user_info')) || {};
    var  userId = user.id;
    function twbsPagination(total) {
        //分页按钮
      
        Page({
			num:Math.ceil(total / 21),					//页码数
			startnum:1,				//指定页码
			elem:$('#pagination_b'),		//指定的元素
			callback:function(page){	//回调函数
                if (page != 1) {
                    onoff = true;
                }
                if (onoff) {
                    requestGoodsList(page - 1);
                    $('html,body').animate({scrollTop:$('.hof_goods_list ').offset().top-80}, 500);

                }
			}
		});
    };
    requestGoodsList(0);
    function requestGoodsList(page) {
        var params = {
            "hof_cat_url": "zhongmeixie",
            "page": page,
            "size": 21
        };
        send_ajax('post', '/api/hof/goods_list', params, function callback(res) {
            var html = "";
            if (res.code == 200&&res.data.content) {
                var goodsIdArr=[];
                if(pageOnoff){
                    twbsPagination(res.data.totalElements);
                    pageOnoff=false;
                }
                $('#totalNum').html(res.data.totalElements); //共有多少商品。
                var data = res.data.content;
                if (data.length > 0) {
                    for (var i = 0; i < data.length; i++) {
                        goodsIdArr.push(data[i].id)
                    };
                    var param={
                        user_id: userId ? userId : 0,
                        goodsIdList: goodsIdArr.join(',')
                    }
                    send_ajax('get', '/api/goods/status', param, function callback(res) {
                        if(res.code==200&&res.data){
                            $('.goods_list').html('');  
                            var result = res.data;
                            for(var i = 0;i<data.length;i++){
                                var a_goods = data[i];
                                var goodsId = a_goods.id;
                                if(result[goodsId] != undefined){
                                    a_goods.goodsPrice = result[goodsId].price;
                                    a_goods.statue = result[goodsId].goodsStatus?result[goodsId].goodsStatus:'';
                                };
                                html += " <li>\n <div class=\"hof_goodsinfo\">\n<i class=\"goodsStatue\ "+'goods_status'+a_goods.statue+"\"></i>\n<a href=\"/goods-" + a_goods.id + ".html\" class=\"goods_img\" target=\"_blank\"><img src=\"" + (a_goods.thumb ? isImgHttp(a_goods.thumb) : '//static.yczihua.com/images/201803/1520979355119049923.jpg') + "\" alt=\"" + a_goods.name + "\"></a>\n                                    </div>\n                                    <div class=\"msg\">\n                                        <a href=\"/goods-" + a_goods.id + ".html\" target=\"_blank\">" + a_goods.name + "</a>\n                                        <strong>" + a_goods.goodsAdName + "</strong>\n                                    </div>\n                                    <div class=\"price\">\n                                        <span>\u6613\u4ECE\u4EF7: <span class=\"money\"><i>\uFFE5</i>" + a_goods.goodsPrice + "</span> </span>\n                                        <a href=\"/goods-" + a_goods.id + ".html\" target=\"_blank\">\u70B9\u51FB\u67E5\u770B</a>\n                                    </div>\n                                </li>";

                            }
                          $('.goods_list').html(html);  
                        }
                    });

                    
                } else {
                    $('.goods_list').append('<li>没有数据</li>');
                }
            }
        });
    };
    //推荐名家
    var recommendParam = {
        "hof_cat_url": "zhongmeixie",
        "page": 0,
        "size": 8
    };
    send_ajax('post', '/api/hof/artist_list', recommendParam, function callback(res) {
        var html = '';
        var recommendHtml = "";
        if (res.code == 200) {
            var data = res.data.content;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<li><a href=\"/halloffame/mj/" + data[i].hofArtist.url + "/goods_list/\" target=\"_blank\">" + data[i].name + "</a></li>";
                    recommendHtml += " <li class=\"swiper-slide \">\n                                        <div class=\"pic\">\n                                            <a href=\"/mj/zuozhe-" + data[i].id + "/\" target=\"_blank\"><img src=\"" + isImgHttp(data[i].portrait) + "\" alt=\"" + data[i].name + "\"></a>\n                                        </div>\n                                        <div class=\"pic_content\">\n                                            <p><a href=\"/mj/zuozhe-" + data[i].id + "/\" target=\"_blank\">" + data[i].name + "&nbsp&nbsp" + data[i].professionalTitle.split(',')[0] + ("  </a></p>\n                                            <p><span> " + data[i].profession + "</span></p>\n                                        </div>\n                                    </li>");
                };
                $('.swiper-wrapper').html(recommendHtml);
                $('.famous').html(html); //中美协艺术家nav
            } else {
                $('.swiper-wrapper').html('<li>没有数据</li>');
                $('.famous').html('<li>没有数据</li>'); //中美协艺术家nav
            }
        };
        //启用轮播图
        var mySwiper = new Swiper('.swiper-container', {
            slidesPerView: 4,
            loop: true,
            observer: true,
            observeParents: true,
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev'
            }
        });
    });
});